﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;


using cz.uhul.DSMLv2;
using cz.uhul.DSMLv2.Server.Sql;

namespace testDSML
{
  public class testModify
  {



    public static void go()
    {


      LdModifyResponse mdr = _deleteAttribute("cn=10000497,cn=mze,cn=users,o=mze,c=cz", "SN", null);
      mdr = _addAttribute("cn=10000497,cn=mze,cn=users,o=mze,c=cz", "SN", "Radouš");
    
    
    }






    private static LdModifyResponse _addAttribute(LdDistinguishedName dn, string attrName, string attrValue)
    {
      LdModifyRequest md = new LdModifyRequest()
      {
        DistinguishedName = dn
        ,Attributes = new LdModifyAttrCollection()
        {
          new LdModifyAttr()
          {
            Name = attrName
            ,Values = new ObservableCollection<string>()
            {
              attrValue
            }
            ,Operation = LdAttrModifyOperationEnum.add
          }
        }
      };

      return md.Execute();

    }




    private static LdModifyResponse _deleteAttribute(LdDistinguishedName dn, string attrName, string attrValue)
    {
      LdModifyRequest md;

      //LdModifyResponse mr = addAttribute(dn, attrName, attrValue);

      md = new LdModifyRequest()
      {
        DistinguishedName = dn
        ,Attributes = new LdModifyAttrCollection()
          {
            new LdModifyAttr()
            {
              Name = attrName
              ,Operation = LdAttrModifyOperationEnum.delete
            }
          }
      };

      if (attrValue != null)
        md.Attributes[0].Values = new ObservableCollection<string>()
        {
          attrValue
        };

      return md.Execute();
    }



  }

}
